package com.siwei.mes.service.system.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.siwei.mes.common.query.PageQuery;
import com.siwei.mes.entity.system.AggregateWater;
import com.siwei.mes.mapper.system.AggregateWaterMapper;
import com.siwei.mes.service.system.AggregateWaterService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

import static com.siwei.mes.common.exception.handler.MessageHandler.assertTrue;

/**
 * 含水率(AggregateWater)表服务实现类
 *
 * @author linzi
 * @since 2023-12-01 22:37:52
 */
@Service
public class AggregateWaterServiceImpl implements AggregateWaterService {
    @Resource
    private AggregateWaterMapper aggregateWaterMapper;

    @Override
    public Long create(AggregateWater entity) {
        aggregateWaterMapper.insertSelective(entity);
        return entity.getId();
    }

    @Override
    public void update(AggregateWater entity) {
        AggregateWater aggregateWater = aggregateWaterMapper.selectByPrimaryKey(entity.getId());
        assertTrue(aggregateWater == null, "含水率信息不存在");
        aggregateWaterMapper.updateByPrimaryKeySelective(entity);
    }

    @Override
    public void delete(Long id) {
        AggregateWater aggregateWater = aggregateWaterMapper.selectByPrimaryKey(id);
        assertTrue(aggregateWater == null, "含水率信息不存在");
        aggregateWaterMapper.deleteByPrimaryKey(id);
    }

    @Override
    public PageInfo<AggregateWater> getPage(PageQuery<AggregateWater, AggregateWater> query) {
        AggregateWater searchParam = query.getParams();
        return PageHelper.startPage(query.getPageNum(), query.getPageSize())
                .doSelectPageInfo(() -> aggregateWaterMapper.getList(searchParam));
    }

    @Override
    public AggregateWater loadById(Long id) {
        return aggregateWaterMapper.loadById(id);
    }

    @Override
    public List<AggregateWater> getAll(AggregateWater entity) {
        return aggregateWaterMapper.getList(entity);
    }

    @Override
    public AggregateWater getLastInfo(AggregateWater entity) {
        return aggregateWaterMapper.getLastInfo(entity);
    }
}
